package com.beone.smart.smartBeauty.controller.webApi;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.beone.smart.smartBeauty.dao.BeautyDeviceDao;
import com.beone.smart.smartBeauty.dao.ProductGatherDao;
import com.beone.smart.smartBeauty.dao.SkinGatherDao;
import com.beone.smart.smartBeauty.dao.SkinRankDao;
import com.beone.smart.smartBeauty.model.dto.UserDto;
import com.beone.smart.smartBeauty.model.dto.UserGatherDto;
import com.beone.smart.smartBeauty.model.entity.BeautyDeviceDO;
import com.beone.smart.smartBeauty.model.entity.RecommendArticleDO;
import com.beone.smart.smartBeauty.model.result.ResultEntity;
import com.beone.smart.smartBeauty.model.result.ResultTool;
import com.beone.smart.smartBeauty.service.intf.RecommendService;
import com.beone.smart.smartBeauty.utils.LocalTimeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by bruce on 20/2/19 -- 15:59
 */
@Api(description = "大屏")
@Slf4j
@RestController
@RequestMapping(value = "/bigScreen")
public class BigScreenController {
    @Autowired
    private SkinGatherDao skinGatherDao;
    @Autowired
    private RecommendService recommendService;
    @Autowired
    private BeautyDeviceDao beautyDeviceDao;
    @Autowired
    private SkinRankDao skinRankDao;
    @Autowired
    private ProductGatherDao productGatherDao;

    /**
     * 1
     */
    @ApiOperation(value = "累计用户", notes = "查询数据")
    @GetMapping(value = "/totalPeopleNum")
    public ResultEntity totalPeopleNum() {
        HashMap<String, Integer> hashMap = new HashMap<>();
        hashMap.put("totalPeopleNum", 5);
        return ResultTool.ok(hashMap);
    }

    /**
     * 2
     */
    @ApiOperation(value = "肤质统计", notes = "查询")
    @GetMapping(value = "/skinGather")
    public ResultEntity skinStatistics() {
        return ResultTool.ok(skinGatherDao.skinGatherCount());
    }

    /**
     * 3
     */
    @ApiOperation(value = "用户统计", notes = "列表查询")
    @GetMapping(value = "/userGather")
    public ResultEntity userGather() {
        List<UserDto> list = new ArrayList<>();
        list.add(new UserDto("马振徽", "testurl", "北京", "18328435871", LocalTimeUtil.getDateTime()));
        list.add(new UserDto("郑伟", "testurl", "四川", "18958435271", LocalTimeUtil.getDateTime()));
        list.add(new UserDto("张广辉", "testurl", "重庆", "18328435871", LocalTimeUtil.getDateTime()));
        list.add(new UserDto("王海琴", "testurl", "深圳", "1318435871", LocalTimeUtil.getDateTime()));
        list.add(new UserDto("汪正才", "testurl", "广州", "15328435871", LocalTimeUtil.getDateTime()));
        UserGatherDto userGatherDto = new UserGatherDto();
        userGatherDto.setCurrentPeopleAmount(list.size());
        userGatherDto.setUserList(list);
        return ResultTool.ok(userGatherDto);
    }

    /**
     * 4
     */
    @ApiOperation(value = "肤质测试排名", notes = "列表查询")
    @GetMapping(value = "/skinRank")
    public ResultEntity skinRank() {
        return ResultTool.ok(skinRankDao.getList());
    }

    /**
     * 5
     */
    @ApiOperation(value = "智能美容设备", notes = "列表查询")
    @GetMapping(value = "/beautyDevice")
    public ResultEntity beautyDevice() {
        LambdaQueryWrapper<BeautyDeviceDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(BeautyDeviceDO::getJoinDate);
        return ResultTool.ok(beautyDeviceDao.selectList(queryWrapper));
    }

    /**
     * 6
     */
    @ApiOperation(value = "方案排名", notes = "列表查询")
    @GetMapping(value = "/articleRank")
    public ResultEntity articleRank() {
        LambdaQueryWrapper<RecommendArticleDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(RecommendArticleDO::getReadNumber);
        return ResultTool.ok(recommendService.list(queryWrapper));
    }

    /**
     * 7
     */
    @ApiOperation(value = "产品统计", notes = "查询（图表展示）")
    @GetMapping(value = "/productGather")
    public ResultEntity productGather() {
        return ResultTool.ok(productGatherDao.getList());
    }

}
